package interfaz;
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.LayoutStyle.ComponentPlacement;
import javax.swing.ListSelectionModel;
import javax.swing.UIManager;
import javax.swing.border.EmptyBorder;
import javax.swing.border.LineBorder;


public class EliminarArtefacto extends JDialog {

	private static String title=new String("Eliminar artefactos o afirmaciones");
	private final JPanel contentPanel = new JPanel();
	private JButton button;
	private JButton button_1;
	private JList<String> list;

	/**
	 * Launch the application.
	 */
	

	/**
	 * Create the dialog.
	 */
	public EliminarArtefacto(JFrame parent,String[] s) {
		super(parent,title,true);
		setBounds(100, 100, 450, 300);
		getContentPane().setLayout(new BorderLayout());
		contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5));
		getContentPane().add(contentPanel, BorderLayout.CENTER);
		
		//list = new JList<String>(s);
		list=new JList<String>();
		list.setListData(s);
		list.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
		JScrollPane listScroller = new JScrollPane(list);
		listScroller.setPreferredSize(new Dimension(250, 80));
		listScroller.setBorder(new LineBorder(UIManager.getColor("TextField.shadow")));
		button = new JButton("OK");
		button.addActionListener(new ActionListener()	{

			@Override
			public void actionPerformed(ActionEvent arg0) {
				//list=new JList(list.getSelectedValues());
				dispose();
			}		
		});
		button.setActionCommand("OK");
		button_1 = new JButton("Cancel");
		button_1.addActionListener(new ActionListener()	{

			@Override
			public void actionPerformed(ActionEvent e) {
				list = new JList();
				dispose();
			}		
		});
		
		addWindowListener(new WindowAdapter() {
		    
		    public void windowClosing(WindowEvent e) {
		    	list = new JList();
				dispose();
		    }
		});
		
		button_1.setActionCommand("Cancel");
		GroupLayout gl_contentPanel = new GroupLayout(contentPanel);
		gl_contentPanel.setHorizontalGroup(
			gl_contentPanel.createParallelGroup(Alignment.LEADING)
				.addGroup(gl_contentPanel.createSequentialGroup()
					.addContainerGap()
					.addGroup(gl_contentPanel.createParallelGroup(Alignment.LEADING)
						.addComponent(listScroller, GroupLayout.DEFAULT_SIZE, 404, Short.MAX_VALUE)
						.addGroup(Alignment.TRAILING, gl_contentPanel.createSequentialGroup()
							.addComponent(button, GroupLayout.PREFERRED_SIZE, 47, GroupLayout.PREFERRED_SIZE)
							.addGap(18)
							.addComponent(button_1, GroupLayout.PREFERRED_SIZE, 65, GroupLayout.PREFERRED_SIZE)
							.addGap(9)))
					.addContainerGap())
		);
		gl_contentPanel.setVerticalGroup(
			gl_contentPanel.createParallelGroup(Alignment.LEADING)
				.addGroup(gl_contentPanel.createSequentialGroup()
					.addContainerGap()
					.addComponent(listScroller, GroupLayout.DEFAULT_SIZE, 212, Short.MAX_VALUE)
					.addPreferredGap(ComponentPlacement.RELATED)
					.addGroup(gl_contentPanel.createParallelGroup(Alignment.BASELINE)
						.addComponent(button)
						.addComponent(button_1)))
		);
		contentPanel.setLayout(gl_contentPanel);
		setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE);
		setVisible(true);
	}
	public String getListItem(int i)
	{
		return (String) list.getModel().getElementAt(i);
	}
	
	public int getListSize()
	{
		return list.getModel().getSize();
	}
	
	public int getSelectedIndex()
	{
		return list.getSelectedIndex();
	}
	
	public String getSelectedValue()
	{
		return list.getSelectedValue();
	}
}
